# 实现公共断言
import json

import app


def common_assert(dy, response, expect_staus_code, expect_success, expect_code, expect_message):
    res_json = response.json()
    print(res_json)
    dy.assertEqual(expect_staus_code, response.status_code)
    dy.assertEqual(expect_success, res_json.get("success"))
    dy.assertEqual(expect_code, res_json.get("code"))
    dy.assertIn(expect_message, res_json.get("message"))


# 读取外部文件中的测试数据
def read_file(file_name):
    # 读取文件的路径
    file_path = app.PROJECT_PATH + "\data\{}.json".format(file_name)
    # file_path = "E:\\黑马就业班\\5.09\day06\\04_代码\\IHRMApiTestProject\\data\\login_case.json"

    # 获取外部文件中的测试数据

    with open(file_path, encoding="utf-8") as f:
        # 将读取到的测试数据解析为json
        #
        json_data = json.load(f)
        print("获取外部文件中的测试数据:", json_data)

    # 将测试数据写入到列表嵌套元组的变量中
    data_list = []
    for case_data in json_data:
        case_data_tuple = tuple(case_data.values())
        data_list.append(case_data_tuple)
    print("最终返回的的测试数据:", data_list)
    return data_list

    # 返回列表嵌套元组的变量


if __name__ == '__main__':
    read_file("login_case")
